package edu.sctu.wangfuxin.day20150614.testIO;

import java.io.*;

import static java.lang.System.in;

/**
 * Created by user06 on 2015/6/14.
 */
public class IOTest {
    int countbyte = 0;
    int countbyte1 = 0;
    int count = 0;
    byte[] buffer = new byte[1024];
    FileInputStream fileInputStream;
    FileOutputStream fileOutputStream;
    FileOutputStream fileOutputStream1;

    /**
     * 测试FileInputStream  FileOutputStream
     */
    public void test() {
        try {
            fileInputStream = new FileInputStream("D:\\TestIO\\梅西.jpg");
            fileOutputStream = new FileOutputStream("D:\\TestIO\\梅西1.jpg");
            fileOutputStream1 = new FileOutputStream("D:\\TestIO\\梅西2.jpg");
            try {
                while((countbyte = fileInputStream.read())!=-1){
                    count += countbyte;
                    System.out.println(countbyte);
                    fileOutputStream.write(countbyte);

                }
                while((countbyte1 = fileInputStream.read(buffer))!=-1){
                    fileOutputStream1.write(buffer,0,countbyte1);
                }
                System.out.println(count);
                fileOutputStream.flush();
                fileOutputStream1.flush();
                fileInputStream.close();
                fileOutputStream.close();
                fileOutputStream1.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 测试PrintWriter
     * @param
     */
    public void testPrintWriter() throws Exception{
        PrintWriter printWriter = new PrintWriter("D:\\TestIO\\TestFileReader1.txt");
        //printWriter.write();

    }

    public static void main(String[] args) throws Exception{
        IOTest io_test = new IOTest();
        //io_test.test();
        io_test.testPrintWriter();
    }
}
